import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import SelectUtil from '@/SelectUtil';
import UnitSpellEvent from '@/event/UnitSpellEvent';
import BuffCommon from 'code/Core/Common/BuffCommon';
import SelectCommon from 'code/Core/Common/SelectCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/* 活力之血 */
export default class DK_VitalityBlood extends AbilityBase {
    static instance: DK_VitalityBlood;
    buffType: AppBuffType = {
        id: 'buff_DK_VitalityBlood',
        art: this.art,
        name: this.abilityName,
        ubertip: '',
        dur: 7,
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Items\\VampiricPotion\\VampPotionCaster.mdl',
        attribute: {},
        interval: 1,
        onInterval: this.onBuffInterval.bind(this),
    };
    onBuffInterval(buff: Buff) {
        let source = buff.getCaster();
        let lv = this.getAbilityLevel(source);
        let dmg = UnitCommon.取生命回复(buff.getParent()) * (9 + lv);
        let es = SelectUtil.getEnemyUnitsInRange(buff.getParent(), 550);
        for (let e of es) {
            DamageSystemInstance.applyPhysicalDamage(e, source, dmg, this.id);
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl', e, 'origin'));
        }
    }
    constructor(id: string) {
        super(id);
        DK_VitalityBlood.instance = this;
        this.init();
        se.onUnitSpellEffect(this.spellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    spellEffect(d: UnitSpellEvent) {
        let u = GetTriggerUnit();
        this.cast(0, 0, u, u, d);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let lv = this.getAbilityLevel(source);
        BuffCommon.addBuff({
            target: source,
            caster: source,
            buffTypeId: this.buffType.id,
            ablityId: this.id,
            attribute: {
                生命恢复增强: 0.8 + 0.2 * lv,
            },
            config: {
                dur: lv,
            },
        });
        // 友军单位产生1半的效果
        let us = SelectCommon.getAllyUnitInRangeExcludeCenterUnit(source, 600);
        for (let u of us) {
            BuffCommon.addBuff({
                target: u,
                caster: source,
                buffTypeId: this.buffType.id,
                ablityId: this.id,
                attribute: {
                    生命恢复增强: 0.4 + 0.1 * lv,
                },
                config: {
                    dur: 7 + lv,
                },
            });
        }
    }
}
